package com.dongdongshop.controller;

import com.dongdongshop.admin.vo.SpecVO;
import com.dongdongshop.common.Result;
import com.dongdongshop.em.PageRequest;
import com.dongdongshop.em.PageResult;
import com.dongdongshop.em.ResultEnum;
import com.dongdongshop.service.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("spec")
public class SpecController {
    @Autowired
    private SpecService specService;

    @PostMapping("findSpecPage")
    public Result brandList(@RequestBody PageRequest<SpecVO> specVO){
        PageResult<SpecVO> specList = specService.specList(specVO);
        return Result.Response(ResultEnum.SUCCESS).setData(specList);
    }

    @PostMapping("addSpec")
    public Result addSpec(@RequestBody SpecVO specVO){
        specService.add(specVO);
        return Result.Response(ResultEnum.SUCCESS);
    }

    //规格回显
    @RequestMapping("getSpecById")
    public Result getSpecById(@RequestParam Long id){
        SpecVO tsvo = specService.getSpecById(id);
        return Result.OK().setData(tsvo);
    }

    @RequestMapping("updateSpec")
    public Result updateSpec(@RequestBody SpecVO specVO){
        specService.update(specVO);
        return Result.OK();
    }

    @PostMapping("delete")
    public Result deleteSpec(@RequestParam Long[] ids){
        specService.deleteSpec(ids);
        return Result.OK();
    }
}
